package org.example.gxpt.mapper;


import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;
import org.example.gxpt.pojo.dto.UserPageQueryDTO;
import org.example.gxpt.pojo.entity.User;

import java.util.List;

@Mapper
public interface UserMapper {

    /**
     * 插入用户
     * @param user
     */
    void insert(User user);

    /**
     * 根据用户名查询
     * @param username
     * @return
     */
    @Select("select * from user where username = #{username}")
    User getUserByUsername(String username);

    /**
     * 根据手机号查询
     * @param phone
     * @return
     */
    @Select("select * from user where phone = #{phone}")
    User getUserByPhone(String phone);

    /**
     * 根据id更新用户数据
     * @param user
     */
    void update(User user);

    /**
     * 分页查询
     * @param userPageQueryDTO
     * @return
     */
    Page<User> pageQuery(UserPageQueryDTO userPageQueryDTO);

    /**
     * 根据id查询用户
     * @param id
     * @return
     */
    @Select("select * from user where id = #{id}")
    User getById(Long id);

    /**
     * 更新用户状态
     * @param id
     * @param status
     */
    @Update("update user set status = #{status} where id = #{id}")
    void updateStatus(@Param("id") Long id, @Param("status") Integer status);

    /**
     * 根据id删除用户
     * @param id
     */
    @Delete("delete from user where id = #{id}")
    void deleteUserById(Long id);

    /**
     * 查询全部用户
     * @return
     */
    @Select("select * from user")
    List<User> listAll();


}
